const express = require('express')
const morgan = require('morgan')
const cors = require('cors')
const router = require('./router/index')
const errHandler = require('./middleware/err-handler')
require('./model/index')
// 导入端口和接口路径设置
const { port, barUrl } = require('./base')
// 创建expres实例
const app = express()
// 日志中间件
app.use(morgan('dev'))
// 配置json解析中间件
app.use(express.json())
// 配置跨域
app.use(cors())
// 配置url解析
// app.use(express.urlencoded())
// 挂载路由
app.use(barUrl, router)
// 挂载统一处理服务端错误中间件
app.use(errHandler())
app.listen(port, () => {
  console.log(`${port}端口有人访问!`)
})